#include "UiRenderScreen.h"

extern HINSTANCE					g_SDHResModuleHandle;

UiRenderScreen::UiRenderScreen()
{

}

UiRenderScreen::~UiRenderScreen()
{
}

BOOL UiRenderScreen::InitUiWin(HWND hWnd)
{
	BOOL bRtn = FALSE;
	LoadiInterItem();

/***************************************************************************/
#if 0
	HDC hdc = GetDC(hWnd);
	HDC memdc = CreateCompatibleDC(hdc);
//	m_hBakDC = CreateCompatibleDC(hdc);
	m_hBitmapBakDC = CreateCompatibleBitmap(hdc, GetWidth(), GetHeight());
	HGDIOBJ oldbmp = SelectObject(memdc, m_hBitmapBakDC);

	RECT prcWin = GetRect();
	for (int i=0; i<GetChildrenCount(); i++)
	{
		UiWin* pWin = GetChild(i);
		if(!pWin)
			continue;

		RECT rcWin = pWin->GetRect();
		OffsetRect(&rcWin, prcWin.left, prcWin.top);
		RECT rcInt = rcWin;
//		if(IntersectRect(&rcInt, prcUpdate, &rcWin)==0)
//			continue;
		printf("pWin(%d) address is 0x%x\r", i, pWin);
	}

//clean
	SelectObject(memdc, oldbmp);
	DeleteDC(memdc);
	ReleaseDC(hWnd, hdc);

#else
	HDC hdc = GetDC(hWnd);
	m_hBakDC = CreateCompatibleDC(hdc);
	m_hBitmapBakDC = CreateCompatibleBitmap(hdc, GetWidth(), GetHeight());
	HGDIOBJ oldbmp = SelectObject(m_hBakDC, m_hBitmapBakDC);

	RECT rcWin = GetRect();
	RECT prcWin = {0, 0, rcWin.right-rcWin.left, rcWin.bottom-rcWin.top};
	RECT prcUpdate = prcWin;
	OnPaint(m_hBakDC, &prcWin, &prcUpdate);

	ReleaseDC(hWnd, hdc);
#endif
/*****************************************************************************/
	return bRtn;
}

void UiRenderScreen::PaintWin(HDC hdc, RECT* prcWin, RECT* prcUpdate)
{
	m_ImgRenderScreen->Draw(hdc, prcWin, false, false);
}

int UiRenderScreen::OnLButtonDown(UINT fwKeys, int xPos, int yPos)
{
	return UiWin::OnLButtonDown(fwKeys, xPos, yPos);
}

int UiRenderScreen::OnLButtonUp(UINT fwKeys, int xPos, int yPos)
{
	return UiWin::OnLButtonUp(fwKeys, xPos, yPos);
}

void UiRenderScreen::LoadiInterItem()
{
	m_ImgRenderScreen = ImagingHelper::GetImageObject(g_SDHResModuleHandle, 9522);
}

BOOL UiRenderScreen::InitImages()
{
	return TRUE;
}
